<template>
  <div class="posttable">
    <el-row type="flex" justify="center">
      <el-col :span="23">
        <div class="addform addForm">
          <el-form :label-position="labelPosition" ref="form" :model="form" :rules="rules">
            <el-row class="change">
              <el-col>
                <el-col :span="5">
                  <el-form-item label="客户名称" prop="workTaskByjfVo.customerName" style="margin-bottom: 10px;">
                    <el-select v-model.trim="form.workTaskByjfVo.customerName" placeholder="请选择客户名称" @change="selectcustomer" disabled>
                      <el-option
                        v-for="item in customerNames"
                        :key="item.id"
                        :label="item.name"
                        :value="item.name">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="5"  :offset="1">
                  <el-form-item label="需求名称" prop="workTaskByjfVo.requireName" style="margin-bottom: 10px;">
                    <el-select v-model.trim="form.workTaskByjfVo.requireName" placeholder="请选择需求名称" disabled>
                      <el-option
                        v-for="(item,index) in postNameList"
                        :key="index"
                        :label="item"
                        :value="item">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
  
                <el-col :span="5" :offset="1">
                  <el-form-item label="职位级别" prop="workTaskByjfVo.postLevel" style="margin-bottom: 10px;">
                    <el-input v-model.trim="form.workTaskByjfVo.postLevel" placeholder="请输入职位级别"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="5" :offset="1">
                  <el-form-item  label="姓名" prop="workTaskByjfVo.name" style="margin-bottom: 10px;">
                    <el-input v-model.trim="form.workTaskByjfVo.name" placeholder="请输入姓名" disabled></el-input>
                  </el-form-item>
                </el-col>
              </el-col>
             
              <el-col>
                <el-col :span="5"  >
                  <el-form-item label="笔试" prop="intweBackCandidate.write" style="margin-bottom: 10px;">
                    <el-input v-model.trim="form.intweBackCandidate.write" placeholder="请输入笔试"></el-input>
                  </el-form-item>
                </el-col>
  
                <el-col :span="5" :offset="1" >
                  <el-form-item label="面谈次数" prop="workTaskByjfVo.type" style="margin-bottom: 10px;">
                    <el-input v-model.trim="form.workTaskByjfVo.type" placeholder="请输入面试次数" disabled></el-input>
                  </el-form-item>
                </el-col>
  
                <el-col :span="5"  :offset="1">
                  <el-form-item label="约面时间" prop="workTaskByjfVo.candidateTime" style="margin-bottom: 10px;">
                    <el-input v-model.trim="form.workTaskByjfVo.candidateTime" placeholder="请输入约面时间" disabled></el-input>
                  </el-form-item>
                </el-col>
  
                <el-col :span="5" :offset="1" >
                  <el-form-item label="到达时间" prop="intweBackCandidate.arriveTime" style="margin-bottom: 10px;">
                    <el-input v-model.trim="form.intweBackCandidate.arriveTime" placeholder="请输入到达时间"></el-input>
                  </el-form-item>
                </el-col>
              </el-col>
              
              <el-col >
                <el-col :span="5">
                  <el-form-item label="面试时长" prop="intweBackCandidate.interviewTime" style="margin-bottom: 10px;">
                    <el-input v-model.trim="form.intweBackCandidate.interviewTime" placeholder="请输入面试时长" ></el-input>
                  </el-form-item>
                </el-col>
  
  
                <el-col :span="5" :offset="1">
                  <el-form-item label="面试结果" prop="intweBackCandidate.interviewResult" style="margin-bottom: 10px;">
                    <el-input v-model.trim="form.intweBackCandidate.interviewResult" placeholder="请输入面试结果"></el-input>
                  </el-form-item>
                </el-col>
  
                <el-col :span="5" :offset="1">
                  <el-form-item label="候选人形象" prop="intweBackCandidate.interviewImage" style="margin-bottom: 10px;">
                    <el-input v-model.trim="form.intweBackCandidate.interviewImage" placeholder="请输入候选人形象"></el-input>
                  </el-form-item>
                </el-col>
  
                <el-col :span="5" :offset="1">
                  <el-form-item label="最终结果" prop="intweBackCandidate.finalResult" style="margin-bottom: 10px;">
                    <el-input v-model.trim="form.intweBackCandidate.finalResult" placeholder="请输入最终结果"></el-input>
                  </el-form-item>
                </el-col>
                <el-col>
              </el-col> 
              <el-col :span="12" >
                <el-form-item label="未通过原因" prop="intweBackCandidate.referReason" style="margin-bottom: 10px;">
                  <el-input type="textarea"  v-model="form.intweBackCandidate.referReason" placeholder="请输入未通过原因" style="width: 100%;" :autosize="{ minRows: 4}"></el-input>
                </el-form-item>
              </el-col>
              </el-col>

              <el-col>
              
              <el-col :span="12" >
                <el-form-item label="筛选简历目前存在的问题" prop="intweBackCandidate.question" style="margin-bottom: 10px;">
                  <el-input type="textarea"  v-model="form.intweBackCandidate.question" placeholder="请输入筛选简历目前存在的问题" style="width: 100%;" :autosize="{ minRows: 4}"></el-input>
                </el-form-item>
              </el-col>
              </el-col>
             <el-col style="margin-top:20px">
                <el-form-item>
                  <el-button class="save" :disabled="senddis" @click="submitForm('form')">提交</el-button>
                  <el-button class="canceL" @click="cancel('form')">取消</el-button>
                </el-form-item>
              </el-col>
            
            </el-row>
          </el-form>
        </div>
      </el-col>
    </el-row>
  
  </div>
</template>
<script>
  import axios from 'axios'
  import qs from 'qs'
  
  export default {
    name: "editwork",
    props: {
      currentData: {
        type: Object
      }
    },
    data() {
      return {
        labelPosition: "top",
       form:{
          intweBackCandidate: {
            write:'',
            arriveTime:'',
            finalResult:'',
            referReason:'',
            question:''

        },
        workTaskByjfVo: {
         
        },
       },
        customerNames: [],
        postNameList: [],
        customerId: '',
        rules: {
          'workTaskByjfVo.customerName': [
            {required: true, message: '请选择客户名称', trigger: 'change'}
          ],
          'workTaskByjfVo.requireName': [
            {required: true, message: '请选择需求名称', trigger: 'change'}
          ],
          'workTaskByjfVo.name':[
            {required: true, message: '请输入姓名', trigger: 'blur'}
          ],
          'intweBackCandidate.interviewResult':[
            {required: true, message: '请输入面试结果', trigger: 'blur'}
          ]
          
        },
        largeerror1: false,
        senddis: false,
        errordialogVisible: false,
        errorinfo: null,
        disabled: false,
        dialogFormVisible: false,
        historydata: [],
        totalcount: null,
        disabled1: false,
        dialogFormVisible1: false,
        historydata1: [],
        totalcount1: null,
        actionurl: null,
        
      }
    },
    created() {
      axios
        .get(this.url + "/demand/getCustomerNames") // 客户名称下拉列表请求
        .then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            this.customerNames = res.data.data;
          }
        });
      this.name = this.currentData.name;
    this.customerName = this.currentData.customerName;
    this.type = this.currentData.type;
     //获取数据
        axios.post(this.url + "/worktaskByjf/selByName", {
        name: this.name,
        customerName:this.customerName,
        type:this.type
      }).then(res => {
        this.unlogin(res.data.code)
        if (res.data.code == 200) {
          if(res.data.data.intweBackCandidate !== null){
            this.form.intweBackCandidate = res.data.data.intweBackCandidate;
          }
          this.form.workTaskByjfVo = res.data.data.workTaskByjfVo;
  

          axios
          .post(this.url + "/interviewFeedBack/getPostName", {
            customer: this.form.workTaskByjfVo.customerName + ""
          })
          .then(res => {
            this.unlogin(res.data.code);
            if (res.data.code == 200) {
              this.postNameList = res.data.data;
            }
          });
        }
      })
      
    },
    methods: {
      initdata() {
        this.senddis = false;
        this.disabled = false;
        this.disabled1 = false;
        this.form = {
         intweBackCandidate: {
         
        },
        workTaskByjfVo: {
         
        },
        };
      },
      //获取需求名称的下拉框数据
      selectcustomer() {
        for (let i = 0, l = this.customerNames.length; i < l; i++) {
          if (this.customerNames[i].name === this.form.customerName) {
            this.kehujiancheng = this.customerNames[i].name;
          }
          if (this.customerNames[i].name === this.form.customerName) {
            this.cusId = this.customerNames[i].id;
          }
        }
        this.form.postName = '';
        this.form.postLevel = '';
        // 职位名称下拉框请求
        axios
          .post(this.url + "/interviewFeedBack/getPostName", {
            customer: this.kehujiancheng + ""
          })
          .then(res => {
            this.unlogin(res.data.code);
            if (res.data.code == 200) {
              this.postNameList = res.data.data;
            }
          });
     
        
      },
       
      
      //提交数据
      submitForm(formName) {
          this.$refs[formName].validate(valid => {
            if (valid) {
              this.senddis = true;
                for (let i = 0, len = this.customerNames.length; i < len; i++) {
                if (this.form.customerName == this.customerNames[i].name) {
                  this.form.customerId = this.customerNames[i].id;
                }
              }
                axios
                  .post(this.url + "/worktaskByjf/upByName", this.form)
                  .then(res => {
                    this.unlogin(res.data.code);
                    if (res.data.code === 200) {
                      this.$emit("getData");
                      this.senddis = false;
                    }
                    this.initdata()
                    this.$refs.form.resetFields()
                  });
             
            
          }
          })
      },
     
      cancel(formName) {
        this.senddis = false;
        this.savedis = false;
        this.historydata = [];
        this.historydata1 = [];
        this.currentPage = 1;
        this.currentPage1 = 1;
        this.selectfile = false;
        this.filetype = true;
        this.filetype1 = true;
        this.file = {};
        this.fileList = [];
        this.file1 = {};
        this.fileList1 = [];
        this.$emit('getData');
        this.$emit('getbackData');
        this.initdata()
        this.$refs.form.resetFields()
      },
   
      
      
    },
    watch: {
      'currentData.id': {
        handler(val, oldval) {
          if (this.show) {
            if (val !== oldval) {
              this.id = val;
              this.getdetail()
            } else {
              this.id = val;
              this.getdetail()
            }
          }
        },
        immediate: true,
        deep: true
      },
    }
  }
</script>
<style scoped>
  .addform {
    color: #333 !important;
  }
  
  .storage {
    width: 150px;
    height: 40px;
    font-size: 16px;
    color: #4e72f3;
    border-radius: 4px;
    margin-right: 43px;
    border-color: #4e72f3;
  }
  
  .save {
    width: 150px;
    height: 40px;
    font-size: 16px;
    color: #fff;
    border-radius: 4px;
    margin-right: 43px;
    background: linear-gradient(to bottom, #5696f8 0%, #4e6ef5 100%);
  }
  
  .canceL {
    width: 150px;
    height: 40px;
    border: 1px solid #4e6ef5;
    font-size: 16px;
    font-weight: 500;
    color: #4e6ef5;
  }
  
  .upload {
    width: 194px;
    height: 44px;
    margin-top: 10px;
    /*margin-bottom: 30px;*/
  }
  
  .pager {
    width: 100%;
    overflow: hidden;
    position: relative;
    margin-top: 10px;
    margin-bottom: 10px;
  }
  
  .el-pagination {
    margin-left: 50%;
    transform: translateX(-50%);
  }
</style>
